package org.aeon.gamechatnest.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.aeon.gamechatnest.common.response.Result;
import org.aeon.gamechatnest.common.response.ResultBuild;
import org.aeon.gamechatnest.pojo.UserInfo;
import org.aeon.gamechatnest.service.UserInfoService;
import org.aeon.gamechatnest.validated.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author : Liys 2024/5/14 11:22
 */
@Validated
@RestController
@RequestMapping("user/info")
@Tag(name = "UserInfoControllerApi", description = "用户信息修改控制器")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    // 程序内部调用无需暴露api
    // @Operation(summary = "新增用户信息")
    // @PostMapping
    // public Result save(@RequestBody @Validated(Add.class) UserInfo userInfo) {
    //     boolean result = userInfoService.save(userInfo);
    //     return ResultBuild.successIf(result).build();
    // }

    @Operation(summary = "删除用户信息")
    @DeleteMapping("/{userId}")
    public Result removeByInfoId(@PathVariable("userId") Long userId) {
        boolean result = userInfoService.removeById(userId);
        return ResultBuild.successIf(result).build();
    }

    @Operation(summary = "通过用户信息id修改用户信息")
    @PutMapping
    public Result modifyByInfoId(@RequestBody @Validated(Update.class) UserInfo userInfo) {
        boolean result = userInfoService.updateById(userInfo);
        return ResultBuild.successIf(result).build();
    }

    @Operation(summary = "通过用户信息id查询用户信息",
            parameters = {@Parameter(name = "infoId", description = "用户信息id")})
    @GetMapping("/search")
    public Result getAllByInfoId(Long userId) {
        UserInfo result = userInfoService.getById(userId);
        return ResultBuild.result().successful().data(result).build();
    }

}
